package ZRH;

public class zrh08 {
    public static void main(String[] args) {
        int[] brr = getOu(1, 10);
        for (int i = 0; i < brr.length; i++) {
            System.out.print(brr[i] + " ");
        }
    }


    /**
     * 先判断m，n的大小关系，从而确定区间始末
     * 构造循环，挑取mn之间的偶数
     * 定义计数器，确定偶数个数，并new同等长度的数组接收
     */
    public static int[] getOu(int n, int m) {
        int count = 0;
        if (n < m) {
            for (int i = n; i <= m; i++) {
                if (i % 2 == 0) {
                    count++;
                }
            }
        }
        if (n > m) {
            for (int i = m; i <= n; i++) {
                if (i % 2 == 0) {
                    count++;
                }
            }
        }
        int[] arr = new int[count];
        //定义索引
        int index = 0;
        if (n < m) {
            for (int i = n; i <= m; i++) {
                if (i % 2 == 0) {
                    arr[index] = i;
                    index++;
                }
            }
        }
        if (n > m) {
            for (int i = m; i <= n; i++) {
                if (i % 2 == 0) {
                    arr[index] = i;
                    index++;
                }
            }
        }
        return arr;
    }
}
